package com.liangtian.mdm.dm.jsp.util;

// import com.liangtian.mdm.activiti.api.entity.ShForm;
// import com.liangtian.mdm.activiti.api.entity.TjForm;
import com.liangtian.mdm.base.dao.JdbcDao;
import com.liangtian.mdm.base.utils.ShiroSessionUtils;
import com.liangtian.mdm.dm.common.constant.TableConst;
import com.liangtian.mdm.dm.common.enums.Flag;
import org.apache.commons.lang3.StringUtils;
import com.liangtian.mdm.dm.config.model.AttrConfig;
import com.liangtian.mdm.dm.jsp.dao.JspActionDao;
import com.liangtian.mdm.dm.jsp.service.AutoCodeService;
import com.liangtian.mdm.dm.listener.CacheUtil;
import com.liangtian.mdm.dm.model.model.Model;
import com.liangtian.mdm.util.StringUtil;
import com.liangtian.mdm.system.mdmDis.target.dao.DispatchServiceDao;
import com.liangtian.mdm.system.mdmDis.target.model.DisService;
import com.liangtian.mdm.system.mdmDis.target.model.DisServiceCondition;
import com.liangtian.mdm.system.business.dao.SysBusinessDao;
import com.liangtian.mdm.system.business.model.SysBusiness;
import com.liangtian.mdm.system.file.dao.SysFileDao;
import com.liangtian.mdm.system.file.model.SysFile;
import com.liangtian.mdm.system.user.model.SysUser;
import com.liangtian.mdm.util.ConstantBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;

@Component
public class SqlUtil {

    ////@Value("${ConstantBean.CURRENT_SESSION_USER}")
    //private String ConstantBean.CURRENT_SESSION_USER;

    @Autowired
    private CacheUtil cacheUtil;

    @Autowired
    private JspActionDao jspActionDao;

    @Autowired
    private JdbcDao jdbcDao;

    @Autowired
    SysFileDao sysFileDao;

    @Autowired
    SysBusinessDao sysBusinessDao;

    @Autowired
    DispatchServiceDao dispatchServiceDao;

    @Autowired
    AutoCodeService autoCodeService;

//	@Autowired
//    SysContentDao sysContentDao;

    /**
     * 生成新增操作的插入sql
     *
     * @param param
     * @return
     */
    public Map<String, Object> genInsertSql(Map<String, Object> param) {
        List<String> fileList = new ArrayList<String>();
        //模型ID
        String modelId = param.get("modelId").toString();
        //表名
        String tableName = param.get("tableName").toString();
        StringBuilder sqlHeader = new StringBuilder();
        StringBuilder sqlValues = new StringBuilder();
        sqlHeader.append("insert into ").append(tableName).append("(");
        sqlValues.append("values(");
        List<AttrConfig> las = cacheUtil.getAttrList(modelId);
        for (AttrConfig attr : las) {
            String colName = attr.getAttrColumn();
            String colType = attr.getAttrType();
            if (attr.getAttrType() != null && colType.endsWith("BLOB")) {
                //把文件的列名保存进去
                fileList.add(attr.getAttrColumn());
                continue;
            }
            //没有参与修改的列忽视掉
            if (param.containsKey(colName.toLowerCase())) {
                sqlHeader.append(colName).append(",");
                if ("checkBoxType".equals(colType)) {
                    String colum = colName.toLowerCase();
                    Set<String> keySet = param.keySet();
                    StringBuffer sb = new StringBuffer();
                    for (String string : keySet) {
                        if (string.equals(colum)) {
                            if (param.get(string).toString().contains("[")) {
                                String[] checkBoxLst = (String[]) param.get(string);
                                String checkValues = "";
                                for (int i = 0; i < checkBoxLst.length; i++) {
                                    checkValues = checkValues + checkBoxLst[i] + ",";
                                }
                                checkValues = checkValues.subSequence(0, checkValues.length() - 1).toString().trim();
                                sb.append(checkValues.toString().trim()).append(",");
                            } else {
                                sb.append(param.get(string).toString()).append(",");
                            }
                        }
                    }
                    sqlValues.append("'").append(sb.substring(0, sb.length() - 1)).append("',");
                } else if ("DATE".equals(colType)) {//保存的时候，将日期格式提取出来
                    String value = (String) param.get(colName.toLowerCase());
                    if (value != null)
                        sqlValues.append("'").append(value).append("',");
                    else
                        sqlValues.append(" null,");
                } else {
                    String value = (String) param.get(colName.toLowerCase());
                    if (value != null)
                        sqlValues.append("'").append(value.trim()).append("',");
                    else
                        sqlValues.append(" null,");
                }
            } else {//忽视的列，但是是复选框的情况下
                if ("checkBoxType".equals(colType)) {
                    sqlHeader.append(colName).append(",");
                    sqlValues.append("'").append("',");
                }

            }
        }

        //获取session中用户
        SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        Map<String, String> cond = new HashMap<String, String>();
        cond.put("tableSeqNextval", tableName + TableConst.SEQUENCESUFFIX + ".nextval");
        String idValue = jspActionDao.selectIdBySeq(cond);
        // 变更从表的新增，版本跟主表一致
        String version = param.get("version") == null ? "0" : param.get("version").toString();
        //pid转换
        String pid = param.get("pid") == null ? "0" : param.get("pid").toString();

        sqlValues.append(idValue).append(", '")
                .append(user.getUserId().longValue()).append("', '")
                .append(user.getUserName()).append("', sysdate, ").append(version).append(",")
                .append(Flag.STATE_0.getCode()).append(", ")
                .append(Flag.STATUS_0.getCode()).append(", ")        // 数据状态
                .append(Flag.DISPATCH_0.getCode()).append(", ")
                .append(StringUtil.safeNull(param.get("mainId"))).append(", ")
                .append(pid);
//			.append(StringUtil.safeNull(param.get("pid"))) ;

        if ("updateAdd".equals(param.get("operType"))) {
            sqlHeader.append("id, creater_id, creater_name, creater_time, version, state, status, dis_flag, mainId, pid, opertype)");
            sqlValues.append(", 'add'").append(") ");
        } else {
            sqlHeader.append("id, creater_id, creater_name, creater_time, version, state, status, dis_flag, mainId, pid)");
            sqlValues.append(") ");
        }

        String sql = sqlHeader.append(sqlValues).toString();
        Map<String, Object> res_Map = new HashMap<>();
        res_Map.put("idValue", idValue);
        res_Map.put("sql", sql);
        res_Map.put("fileList", fileList);
        return res_Map;
    }


    /**
     * 生成接收数据的插入sql
     *
     * @param param
     * @return
     */
    public Map<String, Object> genRecptionDataInsertSql(Map<String, Object> param) {
        List<String> fileList = new ArrayList<String>();
        //模型ID
        String modelId = param.get("modelId").toString();
        //表名
        String tableName = param.get("tableName").toString();
        StringBuilder sqlHeader = new StringBuilder();
        StringBuilder sqlValues = new StringBuilder();
        sqlHeader.append("insert into ").append(tableName).append("(");
        sqlValues.append("values(");
        List<AttrConfig> las = cacheUtil.getAttrList(modelId);
        for (AttrConfig attr : las) {
            String colName = attr.getAttrColumn();
            String colType = attr.getAttrType();
            if (colType.endsWith("BLOB")) {
                //把文件的列名保存进去
                fileList.add(attr.getAttrColumn());
                continue;
            }
            //没有参与修改的列忽视掉
            if (param.containsKey(colName.toLowerCase())) {
                sqlHeader.append(colName).append(",");
                if ("checkBoxType".equals(colType)) {
                    String colum = colName.toLowerCase();
                    Set<String> keySet = param.keySet();
                    StringBuffer sb = new StringBuffer();
                    for (String string : keySet) {
                        if (string.equals(colum)) {
                            if (param.get(string).toString().contains("[")) {
                                String[] checkBoxLst = (String[]) param.get(string);
                                String checkValues = "";
                                for (int i = 0; i < checkBoxLst.length; i++) {
                                    checkValues = checkValues + checkBoxLst[i] + ",";
                                }
                                checkValues = checkValues.subSequence(0, checkValues.length() - 1).toString().trim();
                                sb.append(checkValues.toString().trim()).append(",");
                            } else {
                                sb.append(param.get(string).toString()).append(",");
                            }
                        }
                    }
                    sqlValues.append("'").append(sb.substring(0, sb.length() - 1)).append("',");
                } else if ("DATE".equals(colType)) {//保存的时候，将日期格式提取出来
                    String value = (String) param.get(colName.toLowerCase());
                    if (value != null)
                        sqlValues.append("'").append(value).append("',");
                    else
                        sqlValues.append(" null,");
                } else {
                    String value = (String) param.get(colName.toLowerCase());
                    if (value != null)
                        sqlValues.append("'").append(value).append("',");
                    else
                        sqlValues.append(" null,");
                }
            } else {//忽视的列，但是是复选框的情况下
                if ("checkBoxType".equals(colType)) {
                    sqlHeader.append(colName).append(",");
                    sqlValues.append("'").append("',");
                }

            }
        }

        //获取session中用户
        SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        Map<String, String> cond = new HashMap<String, String>();
        cond.put("tableSeqNextval", tableName + TableConst.SEQUENCESUFFIX + ".nextval");
        String idValue = jspActionDao.selectIdBySeq(cond);
        // 变更从表的新增，版本跟主表一致
        String version = param.get("version") == null ? "0" : param.get("version").toString();
        //pid转换
        String pid = param.get("pid") == null ? "0" : param.get("pid").toString();

        sqlValues.append(idValue).append(", '")
                .append(user.getUserId().longValue()).append("', '")
                .append(user.getUserName()).append("', sysdate, ").append(version).append(",")
                .append(Flag.STATE_4.getCode()).append(", ")
                .append(Flag.STATUS_0.getCode()).append(", ")        // 数据状态
                .append(Flag.DISPATCH_0.getCode()).append(", ")
                .append(StringUtil.safeNull(param.get("mainId"))).append(", ")
                .append(pid);
//			.append(StringUtil.safeNull(param.get("pid"))) ;

        if ("updateAdd".equals(param.get("operType"))) {
            sqlHeader.append("id, creater_id, creater_name, creater_time, version, state, status, dis_flag, mainId, pid, opertype)");
            sqlValues.append(", 'add'").append(") ");
        } else {
            sqlHeader.append("id, creater_id, creater_name, creater_time, version, state, status, dis_flag, mainId, pid)");
            sqlValues.append(") ");
        }

        String sql = sqlHeader.append(sqlValues).toString();
        Map<String, Object> res_Map = new HashMap<>();
        res_Map.put("idValue", idValue);
        res_Map.put("sql", sql);
        res_Map.put("fileList", fileList);
        return res_Map;
    }


    /**
     * 生成从表变更操作的插入sql
     *
     * @param param
     * @return
     * @author xiaoliu
     * @dete 2018-01-15 14:10
     */

    public List<String> genSubBgInsertSql(Map<String, Object> param, List<String> sqls) {
        //模型ID
        String modelId = param.get("modelId").toString();
        //表名
        String tableName = param.get("tableName").toString();
        String originTable = tableName.substring(0, tableName.lastIndexOf("_"));
        String bgId = null, mainDataId = null, IdKey = null;
        //主从表-从表
        bgId = tableName + TableConst.SEQUENCESUFFIX + ".nextVal";
        Map<String, String> m = new HashMap<String, String>();
        m.put("tableSeqNextval", bgId);
        IdKey = jspActionDao.selectIdBySeq(m);
        mainDataId = (String) param.get("mainDataId");

        List<AttrConfig> las = cacheUtil.getAttrList(modelId);
        for (AttrConfig attr : las) {
            String colType = attr.getAttrType();
            if (attr.getAttrType() != null && colType.endsWith("BLOB")) {
                break;
            }
        }
        String subIds = (String) param.get("ids");
        if (!StringUtils.isEmpty(subIds)) {
            String ids[] = subIds.split(",");
            for (int i = 0; i < ids.length; i++) {
                StringBuilder sql = new StringBuilder();//声明一个拼接的sql连接符

                String id = (String) ids[i];//获取原始数据的ID
                String tabName = originTable;
                Map<String, Object> subMap = new HashMap<>();
                subMap.put("id", id);
                subMap.put("tableName", tabName + " t");
                Map<String, Object> dataMap = jspActionDao.queryOne(subMap);

                sql.append("insert into ").append(tableName).append("(");

                String columns = cacheUtil.getColumns(modelId);
                sql.append(columns)
                        .append("id, creater_id, creater_name, state, version, creater_time, origin_id, pid, mainId, status, opertype)");

                //获取session中用户
                SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
                sql.append(" select ").append(columns).append(tableName + TableConst.SEQUENCESUFFIX + ".nextVal").append(", '");
                sql.append(user.getUserId().longValue()).append("', '")
                        .append(user.getUserName()).append("', ")
                        .append(Flag.STATE_0.getCode()).append(", version+1, ");  //数据 版本+1

                String opertype = String.valueOf(param.get("operType"));

                String status = Flag.STATUS_0.getCode(), version = ", version,";
                if (Flag.OPER_3.getCode().equals(opertype)) {
                    status = Flag.STATUS_1.getCode();
                }
                sql.append(" sysdate, ID, pid, ")
                        .append(mainDataId).append(",");

                String dataStatus = (String) dataMap.get("status");
                if ("1".equals(dataStatus)) {//判断从表中的这条数据是冻结状态
                    sql.append(dataStatus).append(", '");
                    sql.append("freeze");
                } else {//数据不是冻结状态
                    sql.append(status).append(", '");
                    sql.append(opertype);
                }
                sql.append("' from ")
                        .append(originTable).append(" where id in (")
                        .append(id).append(") ");
                //.append(param.get("ids")).append(") ");
                sqls.add(sql.toString());
                sql.delete(0, sql.length());
            }
        }

        return sqls;
    }


    /**
     * 生成变更操作的插入sql
     *
     * @param param
     * @return
     */

    public List<String> genBgInsertSql(Map<String, Object> param, List<String> sqls) {
        boolean isFile = false;
        //模型ID
        String modelId = param.get("modelId").toString();
        //表名
        String tableName = param.get("tableName").toString();
        String originTable = tableName.substring(0, tableName.lastIndexOf("_"));
        String bgId = null, mainDataId = null, IdKey = null;
        if (param.get("bgId") == null) {
            //非主从、主从表-从表
            bgId = tableName + TableConst.SEQUENCESUFFIX + ".nextVal";
            Map<String, String> m = new HashMap<String, String>();
            m.put("tableSeqNextval", bgId);
            IdKey = jspActionDao.selectIdBySeq(m);
            mainDataId = (String) param.get("mainDataId");
        } else {
            // 主从表-主表
            bgId = param.get("bgId").toString();
            IdKey = bgId;
        }

        List<AttrConfig> las = cacheUtil.getAttrList(modelId);
        for (AttrConfig attr : las) {
            String colType = attr.getAttrType();
            if (attr.getAttrType() != null && colType.endsWith("BLOB")) {
                isFile = true;
                break;
            }
        }

        StringBuilder sql = new StringBuilder();
        sql.append("insert into ").append(tableName).append("(");

        String columns = cacheUtil.getColumns(modelId);
        sql.append(columns)
                .append("id, creater_id, creater_name, state, version, creater_time, origin_id, pid, mainId, status, opertype)");

        //获取session中用户
        SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        if (param.get("bgId") == null) {//增加判断，如果是从表，则取seq，因为可能有多条数据
            sql.append(" select ").append(columns).append(tableName + TableConst.SEQUENCESUFFIX + ".nextVal").append(", '");
        } else {//主表则取已获取id,下边的附件处理需要用到IdKey
            sql.append(" select ").append(columns).append(IdKey).append(", '");
        }
        sql.append(user.getUserId().longValue()).append("', '")
                .append(user.getUserName()).append("', ")
                .append(Flag.STATE_0.getCode()).append(", version+1, ");  //数据 版本+1

        String opertype = String.valueOf(param.get("operType"));

        String status = Flag.STATUS_0.getCode(), version = ", version,";
        if (Flag.OPER_3.getCode().equals(opertype)) {
            status = Flag.STATUS_1.getCode();
        }
        sql.append(" sysdate, ID, pid, ")
                .append(mainDataId).append(",");
        sql.append(status).append(", '");
        sql.append(opertype);
        sql.append("' from ")
                .append(originTable).append(" where id in (")
                .append(param.get("ids")).append(") ");
        sqls.add(sql.toString());
        sql.delete(0, sql.length());

        if (isFile) {
            //判断每个模型是否有附件属性
            Map<String, Object> Fcond = new HashMap<>();
            Fcond.put("surveyType", param.get("modelId"));
            Fcond.put("dataId", param.get("ids"));
            Fcond.put("operType", "apply");
            List<SysFile> sysFileLst = sysFileDao.queryFilesBySurvey(Fcond);
            Set<String> fileIdLst = new HashSet<String>();
            for (SysFile sysFile : sysFileLst) {
                fileIdLst.add(sysFile.getDataId());
            }

            if (!sysFileLst.isEmpty()) {
                String[] idLst = param.get("ids").toString().split(",");
                for (String id : idLst) {
                    for (String string : fileIdLst) {
                        if (string.equals(id)) {
                            sql.append("insert into sys_file(id, survey_type, file_path, file_size, is_flash, create_time, data_id,")
                                    .append("file_name,file_type,creator,update_time,updator,filecolumn,oper_type)")
                                    .append(" select sys_file" + TableConst.SEQUENCESUFFIX + ".nextVal, survey_type, file_path, file_size,")
                                    .append("is_flash, sysdate," + IdKey + ", file_name, file_type,'")
                                    .append(user.getUserName()).append("',update_time,updator,filecolumn,'" + opertype + "' from sys_file")
                                    .append(" where data_id = ").append(id).append(" and survey_type='").append(param.get("modelId") + "'");
                            sqls.add(sql.toString());
                            sql.delete(0, sql.length());
                        }
                    }
                }
            }
        }
        return sqls;
    }

//	public List<String> genBgInsertSql(Map<String, Object> param,List<String> sqls){
//		boolean isFile = false;
//		//模型ID
//		String modelId = param.get("modelId").toString();
//		//表名
//		String tableName = param.get("tableName").toString();
//		String originTable = tableName.substring(0, tableName.lastIndexOf("_"));
//		String bgId = null, mainDataId = null,IdKey = null;
//		if(param.get("bgId")==null){
//			//非主从、主从表-从表
//			bgId = tableName + TableConst.SEQUENCESUFFIX + ".nextVal";
//			Map<String, String> m = new HashMap<String, String>();
//			m.put("tableSeqNextval", bgId);
//			IdKey = jspActionDao.selectIdBySeq(m);
//			mainDataId = (String)param.get("mainDataId");
//		}else{
//			// 主从表-主表
//			bgId = param.get("bgId").toString();
//			IdKey = bgId;
//		}
//		
//		List<AttrConfig> las = cacheUtil.getAttrList(modelId);
//		for(AttrConfig attr : las){
//			String colType = attr.getAttrType();
//			if(attr.getAttrType()!=null&&colType.endsWith("BLOB")){
//				isFile=true;
//				break;
//			}
//		}
//		
//		StringBuilder sql = new StringBuilder();
//		sql.append("insert into ").append(tableName).append("(");
//		
//		String columns = cacheUtil.getColumns(modelId);
//		sql.append(columns)
//			.append("id, creater_id, creater_name, state, version, creater_time, origin_id, pid, mainId, status, opertype)");
//
//   	 	//获取session中用户
//        SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
//        if(param.get("bgId")==null){//增加判断，如果是从表，则取seq，因为可能有多条数据
//        	sql.append(" select ").append(columns).append(tableName + TableConst.SEQUENCESUFFIX + ".nextVal").append(", '");
//        }else{//主表则取已获取id,下边的附件处理需要用到IdKey
//        	sql.append(" select ").append(columns).append(IdKey).append(", '");
//        }
//        sql.append(user.getUserId().longValue()).append("', '")
//		   .append(user.getUserName()).append("', ")
//		   .append(Flag.STATE_0.getCode()).append(", version+1, ");  //数据 版本+1
//		
//		String opertype = String.valueOf(param.get("operType"));
//
//		String status = Flag.STATUS_0.getCode(), version = ", version,";
//		if(Flag.OPER_3.getCode().equals(opertype)){
//			status = Flag.STATUS_1.getCode();
//		}
//		sql.append(" sysdate, ID, pid, ")
//		   .append(mainDataId).append(",");
//	    sql.append(status).append(", '");
//	    if(param.get("bgId")==null){//表示从表
//	    	String subIds = (String) param.get("ids");
//	    	if(!StringUtils.isEmpty(subIds)){
//	    		String ids[] = subIds.split(",");
//	    		for (int i = 0; i <ids.length; i++) {
//					String id = (String) ids[i];//获取原始数据的ID
//					String tabName = originTable;
//					Map<String,Object> subMap = new HashMap<String,Object>();
//					subMap.put("id", id);
//					subMap.put("tableName", tabName +" t");
//					Map<String, Object> dataMap = jspActionDao.queryOne(subMap);
//					String dataStatus = (String) dataMap.get("status");
//					if("1".equals(dataStatus)){//判断从表中的这条数据是冻结状态
//			    		sql.append("freeze");
//			    	}else{//数据不是冻结状态
//			    		sql.append(opertype);
//			    	}
//				}
//	    	}else{
//	    		sql.append(opertype);
//	    	}
//	    }else{//表示主表
//	    	sql.append(opertype);
//	    }
//		sql.append("' from ")
//		   .append(originTable).append(" where id in (")
//		   .append(param.get("ids")).append(") ");
//		sqls.add(sql.toString());
//		sql.delete(0,sql.length());
//		
//		if(isFile){
//			//判断每个模型是否有附件属性
//			Map<String, Object> Fcond = new HashMap<>();
//			Fcond.put("surveyType", param.get("modelId"));
//			Fcond.put("dataId", param.get("ids"));
//			Fcond.put("operType", "apply");
//			List<SysFile> sysFileLst=sysFileDao.queryFilesBySurvey(Fcond);
//			Set<String> fileIdLst=new HashSet<String>();
//			for (SysFile sysFile : sysFileLst) {
//				fileIdLst.add(sysFile.getDataId());
//			}
//			
//			if(!sysFileLst.isEmpty()){
//				String[] idLst =param.get("ids").toString().split(",");
//				for(String id : idLst) {
//					for (String string : fileIdLst) {
//						if(string.equals(id)){
//							sql.append("insert into sys_file(id, survey_type, file_path, file_size, is_flash, create_time, data_id,")
//								.append("file_name,file_type,creator,update_time,updator,filecolumn,oper_type)")
//								.append(" select sys_file" + TableConst.SEQUENCESUFFIX + ".nextVal, survey_type, file_path, file_size,")
//								.append("is_flash, sysdate," + IdKey + ", file_name, file_type,'")
//								.append(user.getUserName()).append("',update_time,updator,filecolumn,'"+opertype+"' from sys_file")
//								.append(" where data_id = ").append(id).append(" and survey_type='").append(param.get("modelId")+"'");
//							sqls.add(sql.toString());
//							sql.delete(0,sql.length());
//						}
//					}
//				}
//			}
//		}
//		return sqls;
//	}

    /**
     * 生成新增操作的插入sql(用户信息不从session中取)--中纺srm接口用
     *
     * @param param
     * @return
     * @author jyh
     */
    public Map<String, Object> genInsertSql_zf(Map<String, Object> param, SysUser user) {
        List<String> fileList = new ArrayList<String>();
        //模型ID
        String modelId = param.get("modelId").toString();
        //表名
        String tableName = param.get("tableName").toString();
        StringBuilder sqlHeader = new StringBuilder();
        StringBuilder sqlValues = new StringBuilder();
        sqlHeader.append("insert into ").append(tableName).append("(");
        sqlValues.append("values(");
        List<AttrConfig> las = cacheUtil.getAttrList(modelId);
        for (AttrConfig attr : las) {
            String colName = attr.getAttrColumn();
            String colType = attr.getAttrType();
            if (attr.getAttrType() != null && colType.endsWith("BLOB")) {
                //把文件的列名保存进去
                fileList.add(attr.getAttrColumn());
                continue;
            }
            //没有参与修改的列忽视掉
            if (param.containsKey(colName.toLowerCase())) {
                sqlHeader.append(colName).append(",");
                if ("checkBoxType".equals(colType)) {
                    String colum = colName.toLowerCase();
                    Set<String> keySet = param.keySet();
                    StringBuffer sb = new StringBuffer();
                    for (String string : keySet) {
                        if (string.equals(colum)) {
                            if (param.get(string).toString().contains("[")) {
                                String[] checkBoxLst = (String[]) param.get(string);
                                String checkValues = "";
                                for (int i = 0; i < checkBoxLst.length; i++) {
                                    checkValues = checkValues + checkBoxLst[i] + ",";
                                }
                                checkValues = checkValues.subSequence(0, checkValues.length() - 1).toString().trim();
                                sb.append(checkValues.toString().trim()).append(",");
                            } else {
                                sb.append(param.get(string).toString()).append(",");
                            }
                        }
                    }
                    sqlValues.append("'").append(sb.substring(0, sb.length() - 1)).append("',");
                } else if ("DATE".equals(colType)) {//保存的时候，将日期格式提取出来
                    String value = (String) param.get(colName.toLowerCase());
                    if (value != null)
                        sqlValues.append("'").append(value).append("',");
                    else
                        sqlValues.append(" null,");
                } else {
                    String value = (String) param.get(colName.toLowerCase());
                    if (value != null)
                        sqlValues.append("'").append(value).append("',");
                    else
                        sqlValues.append(" null,");
                }
            } else {//忽视的列，但是是复选框的情况下
                if ("checkBoxType".equals(colType)) {
                    sqlHeader.append(colName).append(",");
                    sqlValues.append("'").append("',");
                }

            }
        }

        //获取session中用户
        //SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);

        Map<String, String> cond = new HashMap<String, String>();
        cond.put("tableSeqNextval", tableName + TableConst.SEQUENCESUFFIX + ".nextval");
        String idValue = jspActionDao.selectIdBySeq(cond);
        // 变更从表的新增，版本跟主表一致
        String version = param.get("version") == null ? "0" : param.get("version").toString();
        //pid转换
        String pid = param.get("pid") == null ? "0" : param.get("pid").toString();

        sqlValues.append(idValue).append(", '")
                .append(user.getUserId().longValue()).append("', '")
                .append(user.getUserName()).append("', sysdate, ").append(version).append(",")
                .append(Flag.STATE_0.getCode()).append(", ")
                .append(Flag.STATUS_0.getCode()).append(", ")        // 数据状态
                .append(Flag.DISPATCH_0.getCode()).append(", ")
                .append(StringUtil.safeNull(param.get("mainId"))).append(", ")
                .append(pid);
//			.append(StringUtil.safeNull(param.get("pid"))) ;

        if ("updateAdd".equals(param.get("operType"))) {
            sqlHeader.append("id, creater_id, creater_name, creater_time, version, state, status, dis_flag, mainId, pid, opertype)");
            sqlValues.append(", 'add'").append(") ");
        } else {
            sqlHeader.append("id, creater_id, creater_name, creater_time, version, state, status, dis_flag, mainId, pid)");
            sqlValues.append(") ");
        }

        String sql = sqlHeader.append(sqlValues).toString();
        Map<String, Object> res_Map = new HashMap<>();
        res_Map.put("idValue", idValue);
        res_Map.put("sql", sql);
        res_Map.put("fileList", fileList);
        return res_Map;
    }

    /**
     * 生成分发操作的插入sql
     *
     * @param param
     * @return
     */
    public List<String> genDisInsertSql(Map<String, Object> param) {
        List<String> sqls = new ArrayList<>();
        SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        if (user == null) {
            user = new SysUser();
            user.setUserId(new Long(0));
            user.setUserName("OA审核员");
        }
        //表名
        String originTable = String.valueOf(param.get("tableName"));
        String tabName = originTable.endsWith(TableConst.MODIFYSUFFIX) ? originTable.substring(0, originTable.lastIndexOf("_")) : originTable;
        String disTable = tabName + TableConst.DISPATCHSUFFIX; //分发表
        //模型ID
        String modelId = originTable.endsWith(TableConst.MODIFYSUFFIX) ? originTable.substring(0, originTable.lastIndexOf("_")).split("_")[1] : originTable.split("_")[1];
        //查询业务类型id
        if (param.get("mainTabName").toString() != "") {
            tabName = param.get("mainTabName").toString();
        }
        SysBusiness sysBus = sysBusinessDao.selectBusByTable(tabName);
        //查询可以分发的系统集合
        DisServiceCondition disServiceCondition = new DisServiceCondition();
        disServiceCondition.setSurvey_type_id(sysBus.getBusId());
        List<DisService> disPatchLst = dispatchServiceDao.query_disService(disServiceCondition);

        if (disPatchLst.size() > 0) {

            for (int i = 0; i < disPatchLst.size(); i++) {
                StringBuilder sql = new StringBuilder();
                DisService disService = disPatchLst.get(i);
                sql.append("insert into ").append(disTable).append("(");
                String columns = cacheUtil.getColumns(modelId);
                sql.append(columns)
                        .append("id, creater_id, creater_name, dis_flag, status, version, creater_time, mainId, origin_id,target_id,target_code,target_name)");
                //获取session中用户
                sql.append(" select ").append(columns)
                        .append(disTable).append(TableConst.SEQUENCESUFFIX).append(".nextval, '")
                        .append(user.getUserId().longValue()).append("', '")
                        .append(user.getUserName()).append("', ")
                        .append(Flag.DISPATCH_0.getCode()).append(", ");    // 数据状态

                //现在要在王越写的这块===============================
                //========================================================
                if (param.get("mainTabName").toString() != "") {//说明是从表分发（目前先不管）
                    sql.append(" status, version, sysdate, mainId, ");
                } else {//说明是主表（现在处理这个地方的传值）
                    //param.put("operType", form.getOperType());
                    String operType = (String) param.get("operType");//获取操作类型
                    // 1:新增，2:修改，3:启用，4:停用
//					if("审核".equals(operType)){//如果是提交审核通过
//						sql.append("1").append(", ");
//					}else if("变更".equals(operType)){//如果是变更审核通过
//						sql.append("2").append(", ");
//					}else if("冻结".equals(operType)){//如果是冻结审核通过
//						sql.append("4").append(", ");
//					}else if("解冻".equals(operType)){//如果是解冻审核通过
//						sql.append("3").append(", ");
//					}else{
//						sql.append("0").append(", ");//表示是分发
//					}
                    sql.append("  status,version, sysdate, mainId, ");
                }
                //	sql.append(" status, version, sysdate, mainId, ");//这块需要
                //--这里和刘晶确认过，分发表的origin_id的值要存储主表ID的值，所以这里要进行如下的判断
                String originId = originTable.endsWith(TableConst.MODIFYSUFFIX) ? "origin_id" : "id";
                sql.append(originId + ",");

                sql.append("'").append(disService.getTarget_id()).append("',")
                        .append("'").append(disService.getTarget_code()).append("',")
                        .append("'").append(disService.getTarget_name()).append("'")
                        .append(" from  ")
                        .append(originTable).append(" where id in (")
                        .append(param.get("ids")).append(") ");
                sqls.add(sql.toString());
            }
            //更新原始记录的分发状态
            if (param.get("mainTabName").toString() == "") {//说明是主表
                sqls.add(" update " + originTable + " set dis_flag = " + Flag.DISPATCH_1.getCode()
                        + " where id in (" + String.valueOf(param.get("ids")) + ")");
            }
        }
        System.out.println(sqls);
        return sqls;
    }

    /**
     * 生成单字段修改的更新sql(冻结、解冻)
     *
     * @param param
     * @return
     */
    public String genStatusUpdateSql(Map<String, Object> param) {
        //表名
        String tableName = String.valueOf(param.get("tableName"));
        //主键
        String ids = String.valueOf(param.get("ids"));
        StringBuilder sql = new StringBuilder();
        sql.append("update " + tableName + " set status = '").append(param.get("status")).append("'");
        if (param.get("opertype") != null)
            sql.append(", opertype = '").append(param.get("opertype")).append("'");
        sql.append(" where id in (").append(ids).append(")");
        return sql.toString();
    }

    /**
     * 生成提交操作的更新、日志sql
     *
     * @param param
     * @return
     */
    @Deprecated
    public List<String> genSubmitSql(Map<String, Object> param) {
        //表名
        String tableName = String.valueOf(param.get("tableName"));
        //修改数据ID
        String ids = param.get("ids").toString();
        //模型对象
        String modelId = tableName.split("_")[1];
        Model model = cacheUtil.getModel(modelId);

        StringBuilder sql = new StringBuilder();
        //字典表数据提交 无需审核
        sql.append("update " + tableName + " set state = ");
        if ("1".equals(model.getModelType()))
            sql.append(Flag.STATE_4.getCode());
        else
            sql.append(Flag.STATE_5.getCode());
        sql.append(" where id in (").append(ids).append(")");

        List<String> sqls = new ArrayList<String>();
        sqls.add(sql.toString());

        // 获取session中用户
        SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        // 操作类型
        String operType = Flag.OPER_0.getCode();
        if (tableName.endsWith(TableConst.MODIFYSUFFIX)) {
            operType = Flag.OPER_1.getCode();
        }
        // 插入日志
        StringBuilder logSql = new StringBuilder();
        logSql.append("insert into SYS_APPROVE_HISTORY (id, oper_date, approve_level, status, oper_type, ")
                .append(" survey_type, oper_id, oper_name, data_id) ")
                .append(" values (sys_approve_history_seq.nextval, sysdate, 0, ")
                .append(" ").append(Flag.STATUS_0.getCode())        // 数据状态
                .append(", '").append(operType)                    // 操作类型
                .append("', '").append(tableName)                    // 业务类型
                .append("', '").append(user.getUserId().toString())    //操作人ID
                .append("', '").append(user.getUserName())            //操作人姓名
                .append("', '");

        String[] pks = ids.split(",");
        for (String pk : pks) {
            sqls.add(logSql.toString() + pk + "')");
        }
        return sqls;
    }

//     public List<String> genFlowSubmitSql(TjForm form, boolean needFlow, String modelId) {
//         List<String> sqls = new ArrayList<String>();
//         String tableName = form.getTableName();
//         String dataId = form.getDataId();
//         //表示该条件下提交的数据是不走流程的,不走流程的情况下
//         //用户变更编辑一条数据，只需要对变更编辑的数据
//         //1.更改主表的状态      //2.反更改主表的数据
//         StringBuilder sql = new StringBuilder();
//         sql.append("update " + tableName + " set state = ");
//         //needFlow 判断模型（提交-包括申请提交和变更提交及冻结解冻提交）是不是走流程，如果模型
//         if (needFlow) {//needFlow 为true 的时候，表示该条件下提交的数据是走流程的
//             sql.append(Flag.STATE_5.getCode());
//         } else {
//             sql.append(Flag.STATE_4.getCode());
//             if ("提交".equals(form.getOperType())) { //提交的时候配置编码
//                 autoCodeService.autoCode(form.getTableName().split("_")[1], dataId);//自动附码
//             }
//         }
//
//         sql.append(" where id = '").append(dataId).append("'");
//         sqls.add(sql.toString());
//         //--外运定制化提交逻辑
//         // String sys = SysParamUtil.getParameterValue("systemCode");
//         // if ("sinotrans".equals(sys)) {
//         //     WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
//         //     SinotransSqlUtil spm = (SinotransSqlUtil) wac.getBean("sinotransSqlUtil");
//         //     spm.submitSinotrans(modelId, dataId, sqls);
//         // }
//
// //		List<String> noFLst =	this.genNoFlowSubmitSql(form,needFlow,modelId);//不走流程的模型，添加此方法
// //		if(!noFLst.isEmpty()){
// //			for (String str : noFLst) {
// //				sqls.add(str.toString());
// //			}
// //		}
//         return sqls;
//     }


    //刘晶添加不走流程模块的方法，目前测试有问题
//	public List<String> genNoFlowSubmitSql(TjForm form, boolean needFlow,String modelId){
//		    List<String> noFLst = new ArrayList<String>();
//		    String tableName = form.getTableName();
//			String dataId = form.getDataId();
//			String operType = form.getOperType();  //审核、变更、冻结、解冻、新增
//		  if(!Flag.OPER_2.getDesc().equals(operType)){//申请提交过来的数据
//				Map<String, Object> map = new HashMap<>();
//				map.put("tableName", tableName);
//				map.put("id", dataId);
//				//当前数据详细信息
//				Map<String, Object> current = jspActionDao.queryOne(map);
//				//版本
//				String version = String.valueOf(current.get("version"));
//				//原数据ID
//				String originId = String.valueOf(current.get("originId"));
//				
//				//原始表
//				String originTable=tableName.substring(0, tableName.lastIndexOf("_"));
//				
//				String columns = cacheUtil.getColumns(modelId);
//				//第一次变更
//				if("1".equals(version)){
//					StringBuilder sqlHistory = new StringBuilder();
//					//将原始插入变更
//					sqlHistory.append("insert into ").append(tableName)
//						.append("(").append(columns).append(" id, pid, mainId, state, status, version, ")
//						.append("creater_id, creater_name, creater_time, origin_id, opertype)");
//	
//					sqlHistory.append(" select ").append(columns)
//					   .append(tableName).append(TableConst.SEQUENCESUFFIX).append(".nextval, pid, mainId,")
//					   .append("state, status, version, creater_id, creater_name, creater_time, id, '' from ")
//					   .append(originTable).append(" where id = ").append(originId);
//					   //.append(originTable).append(" where id = ").append(originId);
//					noFLst.add(sqlHistory.toString());	
//				}if(Flag.OPER_4.getDesc().equals(operType)){	//解冻
//					noFLst.add( "update "+ originTable +" set status = "+ Flag.STATUS_0.getCode() +", version=version+1 where id = " 
//						+"(select origin_id from "+tableName+" where id ="+ dataId +")");
//				}else if(Flag.OPER_3.getDesc().equals(operType)){//冻结
//					noFLst.add( "update "+ originTable +" set status = "+ Flag.STATUS_1.getCode() +", version=version+1 where id = " 
//						+"(select origin_id from "+ tableName +" where id ="+ dataId +")");
//				}else if(Flag.OPER_1.getDesc().equals(operType)){//变更
//						//更新原表数据
//						StringBuilder sqlUpd = new StringBuilder();
//						sqlUpd.append("update ").append(originTable).append(" set (").append(columns)
//							.append(" pid, updater_id, updater_name, updater_time, version, state, status) = ");
//	
//						StringBuilder sqlVal = new StringBuilder();
//						sqlVal.append("(select ").append(columns)
//							.append(" pid, creater_id, creater_name, sysdate, version, state, status from ")
//							.append(tableName).append(" where id = ").append(dataId).append(")")
//							.append(" where id = ").append(originId);
//						noFLst.add(sqlUpd.append(sqlVal).toString());
//				}
//			}
//		    return noFLst;
//	}


    /**
     * 获取从表的数据集合
     *
     * @param tableName
     * @param id
     * @return
     */
//	public Map<String, Object> genFlowSubDatasParam(String tableName, String id) {
//		Map<String, Object> result_map = new HashMap<>();
//		Map<String, Object> cond = new HashMap<>();
//		cond.put("tableName", tableName);
//		cond.put("idLst", Arrays.asList(id));
//		cond.put("idType", "MAINID");
//		List<String> idList= jspActionDao.selectSubDataIdList(cond);
//		result_map.put("idLst", idList);
//		if(idList.isEmpty())
//			return result_map;
//		List<Map<String, Object>> datas = jspActionDao.selectSubDatasList(cond);
//		result_map.put("datas", datas);
//		return result_map;
//	}
    public List<Map<String, Object>> genFlowSubDatasParam(String tableName, String id) {
        Map<String, Object> cond = new HashMap<>();
        cond.put("tableName", tableName);
        cond.put("idLst", Arrays.asList(id));
        cond.put("idType", "MAINID");
        return jspActionDao.selectSubDatasList(cond);
    }

    /**
     * 启动流程时，改变从表数据状态(暂不记录日志)
     */
    public String genFlowSubDataTjSql(String tableName, List<String> ids, boolean needFlow) {
        StringBuilder sql = new StringBuilder();
        sql.append("update " + tableName + " set state = ");
        if (needFlow) {
            sql.append(Flag.STATE_5.getCode());
        } else {
            sql.append(Flag.STATE_4.getCode());
        }
        sql.append(" where id in (").append(org.apache.commons.lang3.StringUtils.join(ids, ",")).append(")");
        return sql.toString();
    }

    /**
     * 审核完成时，更新从表数据状态
     */
    // public List<String> genFlowSubDataShSql(ShForm form, String tableName, List<Map<String, Object>> datas) {
    //
    //     boolean isPass = form.isPass();
    //     String operType = form.getOperType();
    //
    //     List<String> sqls = new ArrayList<String>();
    //     StringBuilder sql = new StringBuilder();
    //     StringBuilder sql1 = new StringBuilder();
    //     sql.append("update " + tableName + " set state = ");
    //     if (isPass) {
    //         sql.append(Flag.STATE_4.getCode());
    //         if (Flag.OPER_1.getDesc().equals(operType)) {
    //             //原始表
    //             String originTable = tableName.substring(0, tableName.lastIndexOf("_"));
    //
    //             String modelId = tableName.split("_")[1];
    //             String columns = cacheUtil.getColumns(modelId);
    //             String pModelId = cacheUtil.getModel(modelId).getMaintableId();
    //             //通过变更主表 查询从表新增数据 应反写回的主表数据的ID
    //             String pTable = TableConst.TABLEPREFIX + pModelId + TableConst.MODIFYSUFFIX;
    //             //先删除明细表原表数据 update by jsk
    //             sql1.append("delete from " + originTable + " a where a.mainid = (select b.origin_id from " + pTable + " b where  b.id = '" + form.getDataId() + "')");
    //             sqls.add(sql1.toString());
    //             for (int i = 0; i < datas.size(); i++) {
    //                 Map<String, Object> map = datas.get(i);
    //                 //当前数据属于(变更表明细)新增，则写回原始表
    //                 StringBuilder sqlBack = new StringBuilder();
    //                 //将变更新增插入原始
    //                 sqlBack.append("insert into ").append(originTable).append("(").append(columns).append(" id, pid, ")
    //                         .append("creater_id, creater_name, state, status, version, creater_time, mainid )");
    //                 sqlBack.append(" select ").append(columns)
    //                         .append(originTable).append(TableConst.SEQUENCESUFFIX).append(".nextval, pid, ")
    //                         .append("creater_id, creater_name, '4', status, version, creater_time, ")
    //                         .append("(select a.origin_id from " + pTable + " a where a.id = t.mainid ) mainid from ")
    //                         .append(tableName).append(" t where id = ").append(String.valueOf(map.get("id")));
    //                 sqls.add(sqlBack.toString());
    //             }
    //         }
    //     } else {
    //         sql.append(Flag.STATE_3.getCode());
    //     }
    //     String ids = "";
    //     for (int i = 0; i < datas.size(); i++) {
    //         Map<String, Object> map = datas.get(i);
    //         ids += "," + String.valueOf(map.get("id"));
    //     }
    //     sql.append(" where id in (").append(ids.substring(1)).append(")");
    //     sqls.add(sql.toString());
    //     return sqls;
    // }

//     public List<String> genFlowApproveSql(ShForm form, boolean isEnd, String modelId) {
//         String tableName = form.getTableName();
//         String operType = form.getOperType();  //审核、变更、冻结、解冻、新增
//         String dataId = form.getDataId();
//
//         //生成自动配码
//         StringBuilder val = new StringBuilder();
// //		if(isEnd && form.isPass() && operType.equals("审核")){
// //			autoCodeService.autoCode(modelId,form.getDataId());//自动附码
// //		}
//
//         List<String> sqls = new ArrayList<String>();
//         if (isEnd) {
//             //审核通过
//             if (form.isPass()) {//这个表示是申请界面提交的待审核数据
// //				if(Flag.OPER_0.getDesc().equals(operType)){
//                 if (Flag.OPER_2.getDesc().equals(operType)) {
//                     sqls.add("update " + tableName + " set state = " + Flag.STATE_4.getCode() + val.toString() + " where id = " + dataId);
//                 } else {//这个表示是变更界面提交的待审核数据
//                     sqls.add("update " + tableName + " set state = " + Flag.STATE_4.getCode() + val.toString() + " where id = " + dataId);
//
//                     Map<String, Object> map = new HashMap<>();
//                     map.put("tableName", tableName);
//                     map.put("id", dataId);
//                     //当前数据详细信息
//                     Map<String, Object> current = jspActionDao.queryOne(map);
//                     //版本
//                     String version = String.valueOf(current.get("version"));
//                     //原数据ID
//                     String originId = String.valueOf(current.get("originId"));
//
//                     //原始表
//                     String originTable = tableName.substring(0, tableName.lastIndexOf("_"));
//
//                     String columns = cacheUtil.getColumns(modelId);
//                     //第一次变更
//                     if ("1".equals(version)) {
//                         StringBuilder sqlHistory = new StringBuilder();
//                         //将原始插入变更
//                         sqlHistory.append("insert into ").append(tableName)
//                                 .append("(").append(columns).append(" id, pid, mainId, state, status, version, ")
//                                 .append("creater_id, creater_name, creater_time, origin_id, opertype)");
//
//                         sqlHistory.append(" select ").append(columns)
//                                 .append(tableName).append(TableConst.SEQUENCESUFFIX).append(".nextval, pid, mainId,")
//                                 .append("state, status, version, creater_id, creater_name, creater_time, id, '' from ")
// //							   .append(Flag.OPER_1.getCode()).append("' from ")
//                                 .append(originTable).append(" where id = ").append(originId);
//                         //插入最初记录
//                         sqls.add(sqlHistory.toString());
//                     }
//                     //解冻
//                     if (Flag.OPER_4.getDesc().equals(operType)) {
//                         sqls.add("update " + originTable + " set status = " + Flag.STATUS_0.getCode() + ", version=version+1 where id = "
//                                 + "(select origin_id from " + tableName + " where id =" + dataId + ")");
//                     }
//                     //冻结
//                     else if (Flag.OPER_3.getDesc().equals(operType)) {
//                         sqls.add("update " + originTable + " set status = " + Flag.STATUS_1.getCode() + ", version=version+1 where id = "
//                                 + "(select origin_id from " + tableName + " where id =" + dataId + ")");
//                     }
//                     //变更
//                     else if (Flag.OPER_1.getDesc().equals(operType)) {
// 						/*//当前数据属于(变更表明细)新增，则写回原始表
// 						if(Flag.OPER_6.getCode().equals(current.get("opertype"))){
// 							//变更-新增
// 							operType = Flag.OPER_1.getDesc()+Flag.OPER_6.getDesc();
// 							//父模型
// 							String pModelId = cacheUtil.getModel(modelId).getMaintableId();
// 							//通过变更主表 查询从表新增数据 应反写回的主表数据的ID
// 							String pTable = TableConst.TABLEPREFIX+pModelId+TableConst.MODIFYSUFFIX;
// 							StringBuilder sqlBack = new StringBuilder();
// 							//将原始插入变更
// 							sqlBack.append("insert into ").append(originTable).append("(").append(columns).append(" id, pid, ")
// 							   .append("creater_id, creater_name, state, status, version, creater_time, mainId )");
// 							sqlBack.append(" select ").append(columns)
// 							   .append(originTable).append(TableConst.SEQUENCESUFFIX).append(".nextval, pid, ")
// 							   .append("creater_id, creater_name, state, status, version, creater_time, ")
// 							   .append("(select a.origin_id from "+pTable+" a where a.id = t.mainid ) mainId from ")
// 							   .append(tableName).append(" t where id = ").append(String.valueOf(current.get("id")));
// 							sqls.add(sqlBack.toString());
// 						}else{*/
//                         //更新原表数据
//                         StringBuilder sqlUpd = new StringBuilder();
//                         sqlUpd.append("update ").append(originTable).append(" set (").append(columns)
//                                 .append(" pid, updater_id, updater_name, updater_time, version, state, status) = ");
//
//                         StringBuilder sqlVal = new StringBuilder();
//                         sqlVal.append("(select ").append(columns)
//                                 .append(" pid, creater_id, creater_name, sysdate, version, state, status from ")
//                                 .append(tableName).append(" where id = ").append(dataId).append(")")
//                                 .append(" where id = ").append(originId);
//                         sqls.add(sqlUpd.append(sqlVal).toString());
//
//                         ///---wy---1019---带附件的主数据变更
// //							StringBuffer sqlFile = new StringBuffer();
// //							sqlFile.append("delete from sys_file where survey_type = '"+modelId+"' and data_id = '"+originId+"'  ");
//                         String sqlDelFile = " delete from sys_file where survey_type = '" + modelId + "' and data_id = '" + originId + "' and oper_type='apply'  ";
//                         String sqlInsertFile = "Insert into sys_file (id,survey_type,file_path,file_size,file_Type,file_name,is_Flash,updator,update_time,filecolumn,data_id) "
//                                 + "  select  SYS_FILE_SEQ.nextval, survey_type,file_path,file_size,file_Type,file_name,is_Flash,updator,update_time,filecolumn,data_id from sys_file "
//                                 + " where survey_type = '" + modelId + "' and data_id = " + dataId + " and oper_Type = 'update' ";
//                         String sqlUpdateFile = "update sys_file set data_id = '" + originId + "' ,oper_type = 'apply' where data_id = " + dataId + " and oper_Type is null and survey_type = '" + modelId + "' ";
//                         sqls.add(sqlDelFile);//有附件的时候用来删除此条变更数据对应的主表中的数据的附件
//                         sqls.add(sqlInsertFile);//有附件的时候用来插入变更后的附件
//                         sqls.add(sqlUpdateFile);//用来更新变更后的附件信息
//                         //---wy---1019---带附件的主数据变更
//                         //}
//                     }
//                 }
//             } else {
// //				if(Flag.OPER_0.getDesc().equals(operType)){
//                 if (Flag.OPER_2.getDesc().equals(operType)) {//这个表示是申请界面提交的待审核数据
//                     //只有审核拒绝的状态，没有审核拒绝的原因
// //					sqls.add( "update "+ tableName +" set state = "+ Flag.STATE_3.getCode() +" where id = "+ dataId );
//                     sqls.add("update " + tableName + " set state = " + Flag.STATE_3.getCode() + ",ERROR_TEXT = '" + form.getOpinion() + "' where id = " + dataId);
//                 } else {//这个表示是变更界面提交的待审核数据
//                     //只有审核拒绝的状态，没有审核拒绝的原因
//                     //sqls.add( "update "+ tableName +" set state = "+ Flag.STATE_3.getCode() +" where id = "+ dataId );
//                     sqls.add("update " + tableName + " set state = " + Flag.STATE_3.getCode() + ",ERROR_TEXT = '" + form.getOpinion() + "' where id = " + dataId);
//
//                 }
//             }
//         }
//         return sqls;
//     }

//     public List<String> genWaitFlowApproveSql(ShForm form, boolean isEnd, String modelId) {
//         String tableName = form.getTableName();
//         String operType = form.getOperType();  //审核、变更、冻结、解冻、新增
//         String dataId = form.getDataId();
//
//         List<String> sqls = new ArrayList<String>();
//         if (isEnd) {
//             //审核通过
//             if (form.isPass()) {
//                 if (Flag.OPER_2.getDesc().equals(operType)) {
//                     sqls.add("update " + tableName + " set state = " + Flag.STATE_4.getCode() + " where id = " + dataId);
//                 } else {
//                     sqls.add("update " + tableName + " set state = " + Flag.STATE_4.getCode() + " where id = " + dataId);
//
//                     Map<String, Object> map = new HashMap<>();
//                     map.put("tableName", tableName);
//                     map.put("id", dataId);
//                     //当前数据详细信息
//                     Map<String, Object> current = jspActionDao.queryOne(map);
//                     //版本
//                     String version = String.valueOf(current.get("version"));
//                     //原数据ID
//                     String originId = String.valueOf(current.get("originId"));
//
//                     //原始表
//                     String originTable = tableName.substring(0, tableName.lastIndexOf("_"));
//
//                     String columns = cacheUtil.getColumns(modelId);
//                     //第一次变更
//                     if ("1".equals(version)) {
//                         StringBuilder sqlHistory = new StringBuilder();
//                         //将原始插入变更
//                         sqlHistory.append("insert into ").append(tableName)
//                                 .append("(").append(columns).append(" id, pid, mainId, state, status, version, ")
//                                 .append("creater_id, creater_name, creater_time, origin_id, opertype)");
//
//                         sqlHistory.append(" select ").append(columns)
//                                 .append(originTable).append(TableConst.SEQUENCESUFFIX).append(".nextval, pid, mainId,")
//                                 .append("state, status, version, creater_id, creater_name, creater_time, id, '' from ")
// //							   .append(Flag.OPER_1.getCode()).append("' from ")
//                                 .append(originTable).append(" where id = ").append(originId);
//                         //插入最初记录
//                         sqls.add(sqlHistory.toString());
//                     }
//                     //解冻
//                     if (Flag.OPER_4.getDesc().equals(operType)) {
//                         sqls.add("update " + originTable + " set status = " + Flag.STATUS_0.getCode() + ", version=version+1 where id = "
//                                 + "(select origin_id from " + tableName + " where id =" + dataId + ")");
//                     }
//                     //冻结
//                     else if (Flag.OPER_3.getDesc().equals(operType)) {
//                         sqls.add("update " + originTable + " set status = " + Flag.STATUS_1.getCode() + ", version=version+1 where id = "
//                                 + "(select origin_id from " + tableName + " where id =" + dataId + ")");
//                     }
//                     //变更
//                     else if (Flag.OPER_1.getDesc().equals(operType)) {
//                         //更新原表数据
//                         StringBuilder sqlUpd = new StringBuilder();
//                         sqlUpd.append("update ").append(originTable).append(" set (").append(columns)
//                                 .append(" pid, updater_id, updater_name, updater_time, version, state, status) = ");
//
//                         StringBuilder sqlVal = new StringBuilder();
//                         sqlVal.append("(select ").append(columns)
//                                 .append(" pid, creater_id, creater_name, sysdate, version, state, status from ")
//                                 .append(tableName).append(" where id = ").append(dataId).append(")")
//                                 .append(" where id = ").append(originId);
//                         sqls.add(sqlUpd.append(sqlVal).toString());
//                     }
//                 }
//             } else {
//                 if (Flag.OPER_2.getDesc().equals(operType)) {
//                     sqls.add("update " + tableName + " set state = " + Flag.STATE_3.getCode() + " where id = " + dataId);
//                 } else {
//                     sqls.add("update " + tableName + " set state = " + Flag.STATE_3.getCode() + " where id = " + dataId);
//                 }
//             }
//         }
//         return sqls;
//     }

    /**
     * 审核
     */
    @Deprecated
    public List<String> genApproveSql(Map<String, Object> param) {
        //表名
        String tableName = param.get("tableName").toString();
        //变更表
        String modifyTableName = tableName + TableConst.MODIFYSUFFIX;

        //获取session中用户
        SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        // 插入日志
        StringBuilder sqlHeader = new StringBuilder();
        sqlHeader.append("insert into SYS_APPROVE_HISTORY (id, oper_date, approve_level, ")
                .append(" survey_type, oper_id, oper_name, data_id, opinion, status, oper_type) ")
                .append(" values (sys_approve_history_seq.nextval, sysdate, 1, ")
                .append(" '").append(tableName).append("', '")        // 业务类型
                .append(user.getUserId().toString()).append("', '")    //操作人
                .append(user.getUserName()).append("', ");    //操作人姓名

        String modelId = tableName.split("_")[1];
        List<AttrConfig> attrList = cacheUtil.getAttrList(modelId);
        //生成自动配码
        StringBuilder val = new StringBuilder();
        for (AttrConfig ac : attrList) {
            if ("4".equals(ac.getModuleType()) && "0".equals(String.valueOf(ac.getSetCodeTime()))) {
                // 自定义编码
                String codeRule = ac.getCodeRule(); // 固定码@@属性列@@连接符
                String[] styles = codeRule.split("@@");
                // 固定码
                String prefix = "undefined".equals(styles[0]) ? "" : styles[0];
                // 属性列
                String column = styles[1];
                // 连接符
                String union = "undefined".equals(styles[2]) ? "" : styles[2];

                val.append(", ").append(ac.getAttrColumn()).append(" = '").append(prefix).append("' ");
                if (!"undefined".equals(column)) {
                    String[] cols = column.split(",");
                    for (String col : cols) {
                        val.append(" || '").append(union).append("' || ").append(col.toLowerCase());
                    }
                }
                String seqName = tableName + ac.getAttrColumn();
                //String waterCode = this.autoCode(seqName, Integer.parseInt(ac.getWaterCodeLength()));
                String waterCode = null;
                try {
                    waterCode = jdbcDao.genSeqGetVal(seqName, Integer.parseInt(ac.getWaterCodeLength()));
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new RuntimeException("自动配码失败！");
                }
                //拼接流水码
                val.append(" || '").append(union).append("' || '").append(waterCode).append("' ");
            }
        }

        List<String> sqls = new ArrayList<String>();
        //修改数据ID
        String infos = param.get("infos").toString();
        //组装信息 ID ♀ opinion ♀ Y/N ♀ operType
        String[] items = infos.split("♂");
        for (String item : items) {
            StringBuilder sb = new StringBuilder(sqlHeader);
            String[] info = item.split("♀");
            String operType = info[3]; //审核、变更、冻结、解冻、新增
            //审核通过
            if ("T".equals(info[2])) {
                if (Flag.OPER_2.getDesc().equals(operType)) {
                    sqls.add("update " + tableName + " set state = " + Flag.STATE_4.getCode() + val.toString() + " where id = " + info[0]);
                } else {
                    sqls.add("update " + modifyTableName + " set state = " + Flag.STATE_4.getCode() + val.toString() + " where id = " + info[0]);

                    Map<String, Object> map = new HashMap<>();
                    map.put("tableName", modifyTableName);
                    map.put("id", info[0]);
                    //当前数据详细信息
                    Map<String, Object> current = jspActionDao.queryOne(map);
                    //版本
                    String version = String.valueOf(current.get("version"));
                    //原数据ID
                    String originId = String.valueOf(current.get("originId"));

                    String columns = cacheUtil.getColumns(tableName.substring(2));
                    //第一次变更
                    if ("1".equals(version)) {
                        StringBuilder sqlHistory = new StringBuilder();
                        //将原始插入变更
                        sqlHistory.append("insert into ").append(modifyTableName)
                                .append("(").append(columns).append(" id, pid, mainId, state, status, version, ")
                                .append("creater_id, creater_name, creater_time, origin_id, opertype)");

                        sqlHistory.append(" select ").append(columns)
                                .append(modifyTableName).append(TableConst.SEQUENCESUFFIX).append(".nextval, pid, mainId,")
                                .append("state, status, version, creater_id, creater_name, creater_time, id, '' from ")
//						   .append(Flag.OPER_1.getCode()).append("' from ")
                                .append(tableName).append(" where id = ").append(originId);
                        //插入最初记录
                        sqls.add(sqlHistory.toString());
                    }
                    //解冻
                    if (Flag.OPER_4.getDesc().equals(operType)) {
                        sqls.add("update " + tableName + " set status = " + Flag.STATUS_0.getCode() + ", version=version+1 where id = "
                                + "(select origin_id from " + modifyTableName + " where id =" + info[0] + ")");
                    }
                    //冻结
                    else if (Flag.OPER_3.getDesc().equals(operType)) {
                        sqls.add("update " + tableName + " set status = " + Flag.STATUS_1.getCode() + ", version=version+1 where id = "
                                + "(select origin_id from " + modifyTableName + " where id =" + info[0] + ")");
                    }
                    //变更
                    else if (Flag.OPER_1.getDesc().equals(operType)) {
                        //当前数据属于新增，则写回原始表
                        if (Flag.OPER_6.getCode().equals(current.get("opertype"))) {
                            //变更-新增
                            operType = Flag.OPER_1.getDesc() + Flag.OPER_6.getDesc();
                            //父模型
                            String pModelId = cacheUtil.getModel(modelId).getMaintableId();
                            //通过变更主表 查询从表新增数据 应反写回的主表数据的ID
                            String pTable = TableConst.TABLEPREFIX + pModelId + TableConst.MODIFYSUFFIX;
                            StringBuilder sqlBack = new StringBuilder();
                            //将原始插入变更
                            sqlBack.append("insert into ").append(tableName).append("(").append(columns).append(" id, pid, ")
                                    .append("creater_id, creater_name, state, status, version, creater_time, mainId )");
                            sqlBack.append(" select ").append(columns)
                                    .append(tableName).append(TableConst.SEQUENCESUFFIX).append(".nextval, pid, ")
                                    .append("creater_id, creater_name, state, status, version, creater_time, ")
                                    .append("(select a.origin_id from " + pTable + " a where a.id = t.mainid ) mainId from ")
                                    .append(modifyTableName).append(" t where id = ").append(String.valueOf(current.get("id")));
                            sqls.add(sqlBack.toString());
                        } else {
                            //更新原表数据
                            StringBuilder sqlUpd = new StringBuilder();
                            sqlUpd.append("update ").append(tableName).append(" set (").append(columns)
                                    .append(" pid, updater_id, updater_name, updater_time, version, state, status) = ");

                            StringBuilder sqlVal = new StringBuilder();
                            sqlVal.append("(select ").append(columns)
                                    .append(" pid, creater_id, creater_name, sysdate, version, state, status from ")
                                    .append(modifyTableName).append(" where id = ").append(info[0]).append(")")
                                    .append(" where id = ").append(originId);
                            sqls.add(sqlUpd.append(sqlVal).toString());
                        }
                    }
                }
            } else {
                if (Flag.OPER_2.getDesc().equals(operType)) {
                    sqls.add("update " + tableName + " set state = " + Flag.STATE_3.getCode() + " where id = " + info[0]);
                } else {
                    sqls.add("update " + modifyTableName + " set state = " + Flag.STATE_3.getCode() + " where id = " + info[0]);
                }
            }
            sb.append("'").append(info[0]).append("', '").append(info[1]).append("', '");
            String operRslt = "T".equals(info[2]) ? "1" : "2";
            // 数据状态（0送审、2驳回、1通过、空审核中）
            sb.append(operType).append("','").append(operRslt).append("')");
            sqls.add(sb.toString());
        }
        return sqls;
    }

    //变更
    public String genUpdateSql(Map<String, Object> param) {
        //模型ID
        String modelId = String.valueOf(param.get("modelId"));
        //表名
        String tableName = String.valueOf(param.get("tableName"));
        //操作类型
        String returnBase = String.valueOf(param.get("returnBase"));
        //修改数据ID
        String pk = param.get("id").toString();

        StringBuilder sql = new StringBuilder();
        sql.append("update " + tableName + " set ");
        List<AttrConfig> las = cacheUtil.getAttrList(modelId);
        for (AttrConfig attr : las) {
            String colName = attr.getAttrColumn();
            //没有参与修改的列忽视掉
            if (param.containsKey(colName.toLowerCase())) {
                String colType = attr.getAttrType();
                sql.append(colName).append(" = '");
                if (colType.endsWith("checkBoxType")) {
//					String colum=colName.toLowerCase();
//					StringBuffer sb=new StringBuffer();
//							if(param.get(colum).toString().contains("[")){
//								String [] checkBoxLst  = (String[]) param.get(colum);
//								String checkValues ="";
//								for (int i = 0; i < checkBoxLst.length; i++) {
//									checkValues=checkValues+checkBoxLst[i]+",";
//								}
//								checkValues=checkValues.subSequence(0, checkValues.length()-1).toString().trim();
//								sb.append(checkValues.toString().trim()).append(",");
//							}else{
//								sb.append(param.get(colum).toString()).append(",");
//							}
//					sql.append("'").append(sb.substring(0, sb.length()-1)).append("',");
                    String flag = (String) param.get("flag" + colName.toLowerCase() + "");
                    if ("0".equals(flag)) {
                        String value = (String) param.get(colName.toLowerCase());
                        sql.append(value).append("', ");
                    } else {
                        String[] values = (String[]) param.get(colName.toLowerCase());
                        StringBuffer value1 = new StringBuffer();
                        for (String string : values) {
                            value1.append(string).append(",");
                        }
                        sql.append(value1.substring(0, value1.length() - 1)).append("',");
                    }
                } else {
                    String value = StringUtil.escapeSql(param.get(colName.toLowerCase()));
                    sql.append(value).append("', ");
                }
            } else {//被忽略的项
                String colType = attr.getAttrType();
                if (colType.endsWith("checkBoxType")) {//如果是复选框
                    sql.append(colName).append(" = '");
                    sql.append("").append("',");
                }
            }
        }
        sql.append("updater_time = sysdate, ");

        SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        sql.append("updater_id = '").append(user.getUserId().longValue())
                .append("',  updater_name = '").append(user.getUserName())
                .append("',  state = ");
        if ("wh".equals(returnBase)) { //字典表的维护页面进行修改时不修改状态
            sql.append(Flag.STATE_4.getCode());
        } else {
            sql.append(Flag.STATE_0.getCode());
        }
        sql.append(",  pid = ").append(StringUtil.safeNull(param.get("pid")))
                .append(",  error_text = ''")
                .append(" where id = ").append(pk);
        return sql.toString();
    }

    //变更--中纺
    public String genUpdateSql_zf(Map<String, Object> param, SysUser user) {
        //模型ID
        String modelId = String.valueOf(param.get("modelId"));
        //表名
        String tableName = String.valueOf(param.get("tableName"));
        //操作类型
        String returnBase = String.valueOf(param.get("returnBase"));
        //修改数据ID
        String pk = param.get("id").toString();

        StringBuilder sql = new StringBuilder();
        sql.append("update " + tableName + " set ");
        List<AttrConfig> las = cacheUtil.getAttrList(modelId);
        for (AttrConfig attr : las) {
            String colName = attr.getAttrColumn();
            //没有参与修改的列忽视掉
            if (param.containsKey(colName.toLowerCase())) {
                String colType = attr.getAttrType();
                sql.append(colName).append(" = '");
                if (colType.endsWith("checkBoxType")) {
                    String flag = (String) param.get("flag" + colName.toLowerCase() + "");
                    if ("0".equals(flag)) {
                        String value = (String) param.get(colName.toLowerCase());
                        sql.append(value).append("', ");
                    } else {
                        String[] values = (String[]) param.get(colName.toLowerCase());
                        StringBuffer value1 = new StringBuffer();
                        for (String string : values) {
                            value1.append(string).append(",");
                        }
                        sql.append(value1.substring(0, value1.length() - 1)).append("',");
                    }
                } else {
                    String value = StringUtil.escapeSql(param.get(colName.toLowerCase()));
                    sql.append(value).append("', ");
                }
            } else {//被忽略的项
                String colType = attr.getAttrType();
                if (colType.endsWith("checkBoxType")) {//如果是复选框
                    sql.append(colName).append(" = '");
                    sql.append("").append("',");
                }
            }
        }
        sql.append("updater_time = sysdate, ");

        //SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        sql.append("updater_id = '").append(user.getUserId().longValue())
                .append("',  updater_name = '").append(user.getUserName())
                .append("',  state = ");
        if ("wh".equals(returnBase)) { //字典表的维护页面进行修改时不修改状态
            sql.append(Flag.STATE_4.getCode());
        } else {
            sql.append(Flag.STATE_0.getCode());
        }
        sql.append(",  pid = ").append(StringUtil.safeNull(param.get("pid")))
                .append(",  error_text = ''")
                .append(" where id = ").append(pk);
        return sql.toString();
    }

    //============================标准文档模块操作 ========开始=====================================================================================
    /**
     * 文档新增操作的插入sql----只针对文档操作
     * @param param
     * @return
     */
//	public Map<String, Object> genSysContentInsertSql(Map<String, Object> param){
//		
//		String tableName = param.get("tableName").toString();
//		StringBuilder sqlHeader = new StringBuilder();
//		StringBuilder sqlValues = new StringBuilder();
//		sqlHeader.append("insert into ").append(tableName).append("(");
//		sqlValues.append("values(");
//	
//		//获取session中用户
//	    SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
//	    Map<String,String> cond=new HashMap<String, String>();
//        cond.put("tableSeqNextval", tableName+TableConst.SEQUENCESUFFIX+".nextval");
//        String idValue=jspActionDao.selectIdBySeq(cond);
//        
//	   	sqlValues.append("'").append(idValue).append("', '")
//		            .append((String) param.get("contentName")).append("', '")
//		            .append((String) param.get("forumId")).append("', '")
//		            .append((String) param.get("des")).append("', '")
//		            .append((String) param.get("contentText")).append("',")
//		            .append(Flag.STATE_0.getCode()).append(", '") 	
//					.append((String) param.get("important")).append("',")
//					.append(" sysdate, '").append(user.getUserId()).append("', '")
//					.append(user.getUserName()).append("', '")
//					.append((String) param.get("keyWord")).append("', ")
//					.append(Flag.STATUS_0.getCode()).append(", '") 	
//					.append("', '").append("', '").append("','").append("','").append("','") 		
//					.append((String) param.get("fileId")).append("','")
//	   	            .append("0").append("'");
//			sqlHeader.append("CONTENT_ID,CONTENT_NAME,FORUM_ID,DES,CONTENT_TEXT,STATE,IMPORTANT,OPER_TIME,OPER_USER,OPER_UNAME,KEYWORD,STATUS,UPDATE_TIME,UPDATE_USER,UPDATE_UNAME,SUBMIT_TIME,FORUM_NUM,FILE_ID,VERSION)");
//			sqlValues.append(") ");
//		
//		String sql = sqlHeader.append(sqlValues).toString();
//		Map<String, Object> res_Map=new HashMap<>();
//        res_Map.put("idValue", idValue);
//        res_Map.put("version", "0");
//		res_Map.put("sql", sql);
//		return res_Map;
//	}

    /**
     *
     * <p>TODO 文档审核流程方法 </p>
     * <p>@param form
     * <p>@param isEnd
     * <p>@return </p>
     * @author : xiaoliu
     * @date :2017年5月26日上午9:21:44
     */

//	public List<String> genSysContentFlowApproveSql(ShForm form, boolean isEnd) {
//		String tableName = form.getTableName();
//		String operType = form.getOperType();  //审核、变更、冻结、解冻、新增
//		String dataId = form.getDataId();
//		//生成自动配码
//		StringBuilder val = new StringBuilder();
//		List<String> sqls = new ArrayList<String>();
//		if(isEnd){
//			//审核通过
//			if(form.isPass()){
//				if(Flag.OPER_2.getDesc().equals(operType)){
//					sqls.add( "update "+ tableName +" set state = "+ Flag.STATE_4.getCode() + val.toString() +" where content_id = "+ dataId );
//				}else{
//					sqls.add( "update "+ tableName +" set state = "+ Flag.STATE_4.getCode() + val.toString() +" where content_id = "+ dataId );
//					
//					Map<String, Object> map = new HashMap<>();
//					map.put("tableName", tableName);
//					map.put("contentId", dataId);
//					//当前数据详细信息
//					Map<String, Object> current = sysContentDao.querySysContentDetail(map);
//					//版本
//					String version = String.valueOf(current.get("version"));
//					//原数据ID
//					String originId = String.valueOf(current.get("originId"));
//					
//					//原始表
//					String originTable=tableName.substring(0, tableName.lastIndexOf("_"));
//					
//					//第一次变更
//					if("1".equals(version)){
//						StringBuilder sqlHistory = new StringBuilder();
//						//将原始插入变更
//						sqlHistory.append("insert into ").append(tableName)
//							.append("(").append(" update_id, pid, mainId, state, status, version, ")
//							.append("creater_id, creater_name, creater_time, content_id, opertype)");
//
//						sqlHistory.append(" select ")
//						   .append(tableName).append(TableConst.SEQUENCESUFFIX).append(".nextval, pid, mainId,")
//						   .append("state, status, version, creater_id, creater_name, creater_time, id, '' from ")
//						   .append(originTable).append(" where content_id = ").append(originId);
//						//插入最初记录
//						sqls.add(sqlHistory.toString());
//					}
//					//解冻
//					if(Flag.OPER_4.getDesc().equals(operType)){
//						sqls.add( "update "+ originTable +" set status = "+ Flag.STATUS_0.getCode() +", version=version+1 where id = " 
//							+"(select origin_id from "+tableName+" where id ="+ dataId +")");
//					}
//					//冻结
//					else if(Flag.OPER_3.getDesc().equals(operType)){
//						sqls.add( "update "+ originTable +" set status = "+ Flag.STATUS_1.getCode() +", version=version+1 where id = " 
//							+"(select origin_id from "+ tableName +" where id ="+ dataId +")");
//					}
//					//变更
//					else if(Flag.OPER_1.getDesc().equals(operType)){
//							//更新原表数据
//							StringBuilder sqlUpd = new StringBuilder();
//							sqlUpd.append("update ").append(originTable).append(" set (")
//								.append(" pid, updater_id, updater_name, updater_time, version, state, status) = ");
//
//							StringBuilder sqlVal = new StringBuilder();
//							sqlVal.append("(select ")
//								.append(" pid, creater_id, creater_name, sysdate, version, state, status from ")
//								.append(tableName).append(" where id = ").append(dataId).append(")")
//								.append(" where id = ").append(originId);
//							sqls.add(sqlUpd.append(sqlVal).toString());
//					}
//				}
//			}else{
//				if(Flag.OPER_2.getDesc().equals(operType)){
//					sqls.add( "update "+ tableName +" set state = "+ Flag.STATE_3.getCode() +" where content_id = "+ dataId );
//				}else{
//					sqls.add( "update "+ tableName +" set state = "+ Flag.STATE_3.getCode() +" where content_id = "+ dataId );
//				}
//			}
//		}
//		return sqls;
//	}

    /**
     * 标准文档变更操作的插入sql
     * @param param
     * @return
     */
//	public List<String> genBgSysContentInsertSql(Map<String, Object> param,List<String> sqls){
//		String tableName = param.get("tableName").toString();
//		String originTable = tableName.substring(0, tableName.lastIndexOf("_"));
//		String bgId = null, mainDataId = null,IdKey = null;
//		if(param.get("bgId")==null){
//			//非主从、主从表-从表
//			bgId = tableName + TableConst.SEQUENCESUFFIX + ".nextVal";
//			Map<String, String> m = new HashMap<String, String>();
//			m.put("tableSeqNextval", bgId);
//			mainDataId = (String)param.get("mainDataId");
//		}else{
//			// 主从表-主表
//			bgId = param.get("bgId").toString();
//		}
//		
//		StringBuilder sql = new StringBuilder();
//		sql.append("insert into ").append(tableName).append("(");
//		
//		String columns = cacheUtil.getColumns(modelId);
//		sql.append(columns)
//			.append("id, creater_id, creater_name, state, version, creater_time, origin_id, pid, mainId, status, opertype)");
//
//   	 	//获取session中用户
//        SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
//		sql.append(" select ").append(columns).append(tableName + TableConst.SEQUENCESUFFIX + ".nextVal").append(", '")
//		   .append(user.getUserId().longValue()).append("', '")
//		   .append(user.getUserName()).append("', ")
//		   .append(Flag.STATE_0.getCode()).append(", version+1, ");  //数据 版本+1
//		
//		String opertype = String.valueOf(param.get("operType"));
//		String status = Flag.STATUS_0.getCode(), version = ", version,";
//		if(Flag.OPER_3.getCode().equals(opertype)){
//			status = Flag.STATUS_1.getCode();
//		}
////		if(Flag.OPER_1.getCode().equals(opertype)){
////			version = ", version+1,";
////		}
////		sql.append(version).append(" sysdate, ID, pid, ")
//		sql.append(" sysdate, ID, pid, ")
//		   .append(mainDataId).append(",")
//		   .append(status).append(", '")
//		   .append(opertype).append("' from ")
//		   .append(originTable).append(" where id in (")
//		   .append(param.get("ids")).append(") ");
//		sqls.add(sql.toString());
//		sql.delete(0,sql.length());
//		
//		if(isFile){
//			//判断每个模型是否有附件属性
//			Map<String, Object> Fcond = new HashMap<>();
//			Fcond.put("surveyType", param.get("modelId"));
//			Fcond.put("dataId", param.get("ids"));
//			Fcond.put("operType", "apply");
//			List<SysFile> sysFileLst=sysFileDao.queryFilesBySurvey(Fcond);
//			Set<String> fileIdLst=new HashSet<String>();
//			for (SysFile sysFile : sysFileLst) {
//				fileIdLst.add(sysFile.getDataId());
//			}
//			
//			if(!sysFileLst.isEmpty()){
//				String[] idLst =param.get("ids").toString().split(",");
//				for(String id : idLst) {
//					for (String string : fileIdLst) {
//						if(string.equals(id)){
//							sql.append("insert into sys_file(id, survey_type, file_path, file_size, is_flash, create_time, data_id,")
//								.append("file_name,file_type,creator,update_time,updator,filecolumn,oper_type)")
//								.append(" select sys_file" + TableConst.SEQUENCESUFFIX + ".nextVal, survey_type, file_path, file_size,")
//								.append("is_flash, sysdate," + IdKey + ", file_name, file_type,'")
//								.append(user.getUserName()).append("',update_time,updator,filecolumn,'"+opertype+"' from sys_file")
//								.append(" where data_id = ").append(id).append(" and survey_type='").append(param.get("modelId")+"'");
//							sqls.add(sql.toString());
//							sql.delete(0,sql.length());
//						}
//					}
//				}
//			}
//		}
//		return sqls;
//	}

    /**
     * <p>TODO  在此处添加非物料模块冻结的数据的归档操作</p>
     * <p>@param param
     * <p>@param sqls
     * <p>@return </p>
     *
     * @author : xiaoliu
     * @date :2018年4月20日下午2:45:00
     */
    public List<String> genGdInsertSql(Map<String, Object> param, List<String> sqls) {
        //模型ID
        String modelId = param.get("modelId").toString();
        //表名 T_1882_GD
        String tableName = param.get("tableName").toString();//归档表
        String originTable = tableName.substring(0, tableName.lastIndexOf("_"));//主表
        String bgId = null, IdKey = null;
        bgId = tableName + TableConst.SEQUENCESUFFIX + ".nextVal";
        Map<String, String> m = new HashMap<String, String>();
        m.put("tableSeqNextval", bgId);
        IdKey = jspActionDao.selectIdBySeq(m);

        List<AttrConfig> las = cacheUtil.getAttrList(modelId);
        for (AttrConfig attr : las) {
            String colType = attr.getAttrType();
            if (StringUtils.isEmpty(attr.getAttrType()) && colType.endsWith("BLOB")) {
                break;
            }
        }

        StringBuilder sql = new StringBuilder();
        sql.append("insert into ").append(tableName).append("(");

        String columns = cacheUtil.getColumns(modelId);
        sql.append(columns).append("id, creater_id, creater_name, state, version, creater_time, origin_id, pid, mainId, status )");

        //获取session中用户
        SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        sql.append(" select ").append(columns).append(IdKey).append(", '");
        sql.append(user.getUserId().longValue()).append("', '")
                .append(user.getUserName()).append("', ")
                .append("state, version, ");  //数据 版本+1


//			String status = Flag.STATUS_0.getCode();
        sql.append(" sysdate, ID, pid, ")
                .append("mainId").append(",status");
//		    sql.append(status);
        sql.append(" from ")
                .append(originTable).append(" where id in (")
                .append(param.get("ids")).append(") ");
        sqls.add(sql.toString());
        sql.delete(0, sql.length());
        return sqls;
    }

}
